<?php
/**
 * JITink
 *  Author: sunbirder
 * Date: 2016/08/01
 */

namespace Admin\Controller;

class AdController extends CommonController
{

    /**
     * 广告列表
     */
    public function index()
    {
        if(IS_POST){
            $map = array();
            if($_POST['position_id']){
                $map['ap.id'] = $_POST['position_id'];
            }
            $map = array_merge($map, $this->_search('a.'));
        }
        $model = M()->field("a.*, ap.title as position_title")
            ->table($this->prefix."ad a")
            ->join($this->prefix."ad_position ap ON a.position_id=ap.id", 'LEFT')
            ->where($map)
            ->order('a.id desc');
        $list = $this->slists($model);
        $this->getAdPositionList();
        $this->assign('adList', $list); // 赋值数据集
        $this->display();
    }

    /**
     * 获取广告位置列表
     * @param string $type  return/assign
     */
    private function getAdPositionList($type='assign'){
        $adPositionList = M('AdPosition')->field("*")->where(array('status'=>1))->select();
        if($type=='return')
            return $adPositionList;
        else
            $this->assign('adPositionList', $adPositionList); //广告位
    }
}